<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ModPadres
 *
 * @author EaDeveloper
 */
class ModBenefactor implements EaSoftModule {

    public $title = "Benefactores";
    public $maintenance;
    public $relativePath = "modules/benefactores/";
    public $includePath = "benefactores/";
    public $db;
    public $gridMant;
    public $grdHijos;
    public $grdAlumnos;
    public $instanceName = "ModBenefactor";

    public function __construct() {
        $this->maintenance = new Maintenance();
        $this->maintenance->table = "cllg_benefactor";
        $this->maintenance->title = "Mantenimiento Benefactores";
        $this->maintenance->validations = array("required,RAZON_SOCIAL, Razon social es Requerido",
            "required,TELEFONO, Telefono es Requerido",
            "required,DIRECCION,Direccion es Requerido");

        $this->gridMant = new JGridGenerator();
        $this->gridMant->table = "cllg_benefactor";
        $this->gridMant->fields = array("ID", "RAZON_SOCIAL", "DIRECCION", "EMAIL");
        $this->gridMant->colTypes = array("ID" => "int", "RAZON_SOCIAL" => "text", "DIRECCION" => "text", "EMAIL" => "text");
        $this->gridMant->pk = "ID";

        $this->grdHijos = new JGridGenerator();
        $query = "select s.ID,s.FIRST_NAME,s.SECOND_NAME,s.LAST_NAME,p.BENEFACTOR from cllg_student s
			inner join cllg_student_benefactor p on s.ID=p.STUDENT ";
        $this->grdHijos->query = $query;
        $this->grdHijos->whereParams = array("BENEFACTOR" => "BENEFACTOR");
        $this->grdHijos->fields = array("ID", "FIRST_NAME", "LAST_NAME", "PARENT");
        $this->grdHijos->pk = "ID";

        $this->grdAlumnos = new JGridGenerator();
        $query = "SELECT  cllg_student.ID, cllg_student.FIRST_NAME, cllg_student.LAST_NAME,
                cllg_student_benefactor.BENEFACTOR
        FROM    cllg_student
                LEFT JOIN cllg_student_benefactor ON cllg_student.ID = cllg_student_benefactor.STUDENT
        WHERE   cllg_student_benefactor.BENEFACTOR IS NULL ";
        $this->grdAlumnos->query = $query;
        $this->grdAlumnos->fields = array("ID", "FIRST_NAME", "LAST_NAME", "PARENT");
        $this->grdAlumnos->pk = "ID";
    }

    public function getCssFiles() {
        $this->maintenance->getCssFiles();
    }

    public function getJsFiles() {
        $this->maintenance->getJsFiles();
        ?>
        <script type="text/javascript">
            var AJAX_CORE_URL='<?php echo CORE_PATH ?>?module=<?php echo $this->instanceName; ?>&ajax=true';
        </script>
        <script type="text/javascript" src="<?php echo $this->relativePath; ?>sft.cllg.benef.js"  > </script>
        <script type="text/javascript" src="<?php echo $this->relativePath; ?>sft.cllg.listhijos.js"  > </script>
        <script type="text/javascript" >jQuery.noConflict();</script>
        <script src="<?php echo RELATIVE_PATH; ?>js/prototype.js" type="text/javascript"></script>
        <script src="<?php echo RELATIVE_PATH; ?>js/jsvalidate.js" type="text/javascript"></script>
        <script type="text/javascript">
        <?php
        $this->maintenance->db = $this->db;
        echo $this->maintenance->loadDynValidations();
        echo $this->maintenance->scriptValidations();
        ?>
        </script>
        <?php
    }

    public function getWindowTitle() {
        return $this->title;
    }

    public function main() {
        ModUploader::$PATH_UPLOADS = PATH_UPLOAD_STUDENTS;
        if ($this->maintenance->builder == null) {
            $this->maintenance->init($this->db);
        }
        if (!isEmpty(getParam("operation"))) {
            switch (getParam("operation")) {
                case "listado":
                    $this->gridMant->db = $this->db;
                    $this->gridMant->main();
                    break;
                case "hijos":
                    $this->grdHijos->db = $this->db;
                    $this->grdHijos->main();
                    break;
                case "estudiantes":
                    $this->grdAlumnos->db = $this->db;
                    $this->grdAlumnos->main();
                    break;
                case "edit":
                    include $this->includePath . "edit.php";
                    break;
                case "new":
                    include $this->includePath . "new.php";
                    break;
                default: //switch file
                    include $this->includePath . "data.php";
                    include $this->includePath . "main.php";
            }
        } else {
            include $this->includePath . "main.php";
        }
    }

}
?>
